﻿@using CMS.UI.Models

@helper CMSMenu(CMSMenuModel model)
    {
    <div class="leftMenu">
        <p>@model.Title</p>
        <ul>
        @foreach (var item in model.MenuItems)
        {
            <li>
                @CMSMenuItem(item, 1)
            </li>
        }
        </ul>
    </div>
}

@helper CMSMenu(List<CMSMenuModel> models)
    {
    <div class="leftMenu">
    @foreach (var model in models)
    {
        <p>@model.Title</p>
        <ul>
        @foreach (var item in model.MenuItems)
        {
            <li>
                @CMSMenuItem(item, 1)
            </li>
        }
        </ul>
    }
    </div>
}

@helper CMSMenuItem(CMSMenuItem item, int nestingLevel)
    {
        var html = (WebPageContext.Current.Page as System.Web.Mvc.WebViewPage).Html;
    
    <div class="menuItem clearFix level@(nestingLevel)" data-itemID="@item.MenuItemID" style="padding-left: @(nestingLevel * 10)px;">
        @if (item.IsMove)
        {
        <span>
            <a data-name="btnMove" href="#" class="icon-updown"></a>
        </span>  
        }  
        @if (item.Date.HasValue)
        {
        <span class="dateText">@item.Date.Value.ToString()</span>
        }
        <span class="title">
            @if (!String.IsNullOrEmpty(item.BoldedTitle))
            {
            <b>@html.Raw(item.BoldedTitle)</b>
            }
            @if (!String.IsNullOrEmpty(item.BoldedTitle) && !String.IsNullOrEmpty(item.Title))
            {
            <br />
            }
            @html.Raw(item.Title)
        </span>
        <span class="actions"> 
            @if (item.IsApprove)
            {
            <a data-name="btnApprove" href="#" class="icon-approve" title="@item.ApproveText" data-bind="click: onApprove"></a>
            }
            @if (item.IsExpand)
            {
            <a data-name="btnExpand" href="#" class="icon-expand" title="@item.ExpandText"></a>
            }
            @if (item.IsVisibility)
            {
            <a data-name="btnVisibitily" href="#" class="@(item.Visible ? "icon-on" : "icon-off")" title="@item.VisibilityText" data-bind="click: onToggleVisibility"></a>
            }
            @if (item.IsPreview)
            {
            <a data-name=btnPreview href="@item.PreviewUrl" class="icon-preview" title="@item.PreviewText" target="_blank"></a>
            }
            @if (item.IsComment)
            {
                string commentcss = item.UnauthorizedCommentExists ? "icon-commentre" : (item.AuthorizedCommentExists ? "icon-commentgr" : "icon-comment");
            <a data-name="btnComment" href="#" class="@commentcss" title="@item.CommentsText" data-bind="click: onGetComments"></a>
            }
            @if (item.IsEdit)
            {
            <a data-name="btnEdit" href="#" class="icon-edit" title="@item.EditText" data-bind="click: onEdit"></a>
            }
            @if (item.IsEditImages)
            {
            <a data-name="btnEditImage" href="#" class="icon-image" title="@item.EditImagesText" data-bind="click: onEditImage"></a>
            }
            @if (item.IsManage)
            {
            <a data-name="btnManage" href="#" class="icon-link" title="@item.ManageText" data-bind="click: onManage"></a>
            }
            @if (item.IsAssociation)
            {
            <a data-name="btnAssociation" href="#" class="icon-ass" title="@item.AssociationText" data-bind="click: onAssociate"></a>
            }
            @if (item.IsDelete)
            {
            <a data-name="btnDelete" href="#" class="icon-delete" title="@item.DeleteText" data-bind="click: onDelete"></a>
            }  
        </span>
    </div>
        if (item.SubMenuItems != null && item.SubMenuItems.Count > 0)
        {
            nestingLevel++;
    <ul class="@(item.IsExpand ? "hidden" : String.Empty)">
        @foreach (var subItem in item.SubMenuItems)
        {
        <li>
            @CMSMenuItem(subItem, nestingLevel)
        </li>
        }
    </ul>
        }
}

@helper CMSTopMenu(List<CMS.UI.Models.WebsiteMenuModel> menu, string currentUrl)
    {
        var html = (WebPageContext.Current.Page as System.Web.Mvc.WebViewPage).Html;
    
    <ul class="topmenu">
        @foreach (var item in menu)
        {
            <li>
                @if (String.IsNullOrEmpty(item.Url))
                {
                    <span>@item.Title</span>
                }
                else
                {
                    <a href="@item.Url" @(String.IsNullOrEmpty(item.Target) ? string.Empty : String.Format("target={0}", item.Target))> 
                        @if (item.SubMenuItems != null && item.SubMenuItems.Count > 0)
                        { @html.Raw("&#9660;") } @item.Title
                    </a>
                }
                @if (item.SubMenuItems != null && item.SubMenuItems.Count > 0)
                {
                    @CMSTopMenu(item.SubMenuItems, currentUrl);
                }
            </li>
        }
    </ul>   
}


@helper WebsiteMenu(List<CMS.UI.Models.WebsiteMenuModel> menu, string currentUrl)
    {
    <ul>
        @foreach (var item in menu)
        {
        <li>
            <a href="@('/' + (String.IsNullOrEmpty(item.Url) ? String.Empty : item.Url.Trim('/')))" class="@(item.Url != null && item.Url.Equals(currentUrl) ? "active" : String.Empty)" title="@item.Title">@item.Name</a>
            @if (item.SubMenuItems.Count > 0)
            {
                @WebsiteMenu(item.SubMenuItems, currentUrl)
            }
        </li>
        }
    </ul>
}

@helper WebsiteBreadcrumbs(string companyName, List<CMS.UI.Models.WebsiteMenuModel> breadcrumbs)
    {
        if (breadcrumbs.Count > 0)
        {
        <div class="breadcrumbs">
            <a href="/" title="@companyName">@companyName</a> <span>&gt;</span>
            @for (int i = 0; i < breadcrumbs.Count; i++)
            {
                if (i < breadcrumbs.Count - 1)
                {
                    <a href="@breadcrumbs[i].Url" title="@breadcrumbs[i].Title">@breadcrumbs[i].Name</a> <span>&gt;</span>
                }
                else
                {
                    <span title="@breadcrumbs[i].Title">@breadcrumbs[i].Name</span>
                }
            }
        </div>
        }
}

@helper FormItems(IEnumerable<CMS.BL.Entity.tbl_FormItem> items)
    {
    foreach (var item in items)
    {

         @FormItem(item);
    }
}
@helper FormEmail(CMS.BL.Entity.tbl_FormItem item)
    {
        string email = User as CMS.Utils.CustomPrincipal != null ? (User as CMS.Utils.CustomPrincipal).Email : "";
       <div class="contactFormRow">
      <label for="@item.FormItemID" >@item.FI_Text @(item.FI_Required ? " *" : String.Empty)</label>
        <input id="@item.FormItemID" name="@item.FI_Name" type="email" @(item.FI_Required ? "required=required" : String.Empty) 
            data-val="true" data-val-email="Email Address should have correct email form."  value="@email" />
            </div>
}

@helper FormItem(CMS.BL.Entity.tbl_FormItem item)
    {
    
    <div class="contactFormRow">
    @switch (item.tbl_FormItemType.FIT_Name)
    {
        case "Textbox":
            <label for="@item.FormItemID">@item.FI_Text @(item.FI_Required ? " *" : String.Empty)</label>
            <input id="@item.FormItemID" name="@item.FI_Name" type="text" @(item.FI_Required ? "required=required" : String.Empty) />
                                                                      break;
        case "Email":
            <label for="@item.FormItemID" >@item.FI_Text @(item.FI_Required ? " *" : String.Empty)</label>
            <input id="@item.FormItemID" name="@item.FI_Name" type="email" @(item.FI_Required ? "required=required" : String.Empty) 
            data-val="true" data-val-email="Email Address should have correct email form." />
                                                                       break;
        case "Textarea":
            <label for="@item.FormItemID">@item.FI_Text @(item.FI_Required ? " *" : String.Empty)</label>
            <textarea id="@item.FormItemID" name="@item.FI_Name" @(item.FI_Required ? "required=required" : String.Empty) ></textarea>
                                                             break;
        case "Select":
            <label for="@item.FormItemID">@item.FI_Text @(item.FI_Required ? " *" : String.Empty)</label>
            <select id="@item.FormItemID" name="@("select" + item.FormItemID)" @(item.FI_Required ? "required=required" : String.Empty)>
                @foreach (CMS.BL.Entity.tbl_FormItemValues value in item.tbl_FormItemValues.OrderBy(v => v.FIV_Order))
                {
		        <option value="@value.FIV_Value" @(value.FIV_Selected ? "selected=selected" : String.Empty) >@value.FIV_Text</option>
                }
            </select>
                break;
        case "Checkbox":
            <label>@item.FI_Text @(item.FI_Required ? " *" : String.Empty)</label>
            <div class="valuesContainer">
            @foreach (CMS.BL.Entity.tbl_FormItemValues value in item.tbl_FormItemValues.OrderBy(v => v.FIV_Order))
            {   
                <div>
		            <input id="@value.FormItemValueID" type="checkbox" name="@("checkbox" + value.FIV_FormItemID)" value="@value.FIV_Value" @(item.FI_Required ? "required=required" : String.Empty) @(value.FIV_Selected ? "checked=checked" : String.Empty) /> 
                    <label for="@value.FormItemValueID" class="checkboxLabel">@value.FIV_Text</label>
                </div>
            }
            </div>
            break;
        case "Radio":
            <label>@item.FI_Text @(item.FI_Required ? " *" : String.Empty)</label>
            <div class="valuesContainer">
            @foreach (CMS.BL.Entity.tbl_FormItemValues value in item.tbl_FormItemValues.OrderBy(v => v.FIV_Order))
            {
                <div>
		            <input id="@value.FormItemValueID" type="radio" value="@value.FIV_Value" name="@("radio" + value.FIV_FormItemID)" @(item.FI_Required ? "required=required" : String.Empty)  @(value.FIV_Selected ? "checked=checked" : String.Empty) />
                    <label for="@value.FormItemValueID" class="checkboxLabel">@value.FIV_Text</label>
                </div>
            }
            </div>
            break;
        default:
                                  break;
    }
    </div>
}